/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.plechinger.mcremote.server.strategy;

import com.plechinger.mcremote.data.Request;
import com.plechinger.mcremote.data.RequestMethod;
import com.plechinger.mcremote.data.Response;
import com.plechinger.mcremote.data.ResponseStatus;
import com.plechinger.mcremote.server.craft.CraftLogElement;
import com.plechinger.mcremote.server.craft.CraftServer;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Lukas
 */
@Strategy(method = RequestMethod.LOG)
public class LogStrategy implements ServerStrategy {

    public Response process(Request request) {
        Response response = new Response();
        try {
            List<CraftLogElement> log = CraftServer.getServer().getLog();
            List<CraftLogElement> filt=new ArrayList<CraftLogElement>();
            //Platzhalter filtern
            for (CraftLogElement craftLogElement : log) {
                if (!craftLogElement.getMessage().contains("Unknown console command. ")) {
                    filt.add(craftLogElement);
                }
            }
            response.setResponseObject(filt);
            response.setStatus(ResponseStatus.OK);
            response.setMessage("Server log");
        } catch (Exception ex) {
            response.setStatus(ResponseStatus.ERROR);
            response.setMessage(ex.getLocalizedMessage());
            response.setResponseObject(ex);
        }

        return response;
    }
}
